package io.renren.api.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.api.dao.BtCustomerProBaseinfoDao;
import io.renren.api.entity.BtCategroyManageEntity;
import io.renren.api.entity.BtCustomerProBaseinfoEntity;
import io.renren.api.service.BtCategroyManageService;
import io.renren.api.service.BtCustomerProBaseinfoService;
import io.renren.api.vo.ProBaseInfoVo;
import io.renren.api.vo.ProSimpleVo;



import io.renren.common.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import io.renren.utils.Query;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service("btCustomerProBaseinfoService")
public class BtCustomerProBaseinfoServiceImpl extends ServiceImpl<BtCustomerProBaseinfoDao, BtCustomerProBaseinfoEntity> implements BtCustomerProBaseinfoService {
    @Autowired
    private BtCategroyManageService btCategroyManageService;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String zt="";
        Boolean ztc=false;
        if(params.containsKey("zt")){
            zt= (String)params.get("zt");
            ztc=true;
        }
        String zbcs="";
        Boolean zbcsc=false;
        if(params.containsKey("zbcs")){
            zbcs= (String)params.get("zbcs");
            zbcsc=true;
        }
        String yq="";
        Boolean yqc=false;
        if(params.containsKey("yq")){
            yq= (String)params.get("yq");
            yqc=true;
        }
        String zsdx="";
        Boolean zsdxc=false;
        if(params.containsKey("zsdx")){
            zsdx= (String)params.get("zsdx");
            zsdxc=true;
        }
        String yxgj="";
        Boolean yxgjc=false;
        if(params.containsKey("yxgj")){
            yxgj= (String)params.get("yxgj");
            yxgjc=true;
        }

        Page<BtCustomerProBaseinfoEntity> page;
        page = this.selectPage(
                new Query<BtCustomerProBaseinfoEntity>(params).getPage(),
                new EntityWrapper<BtCustomerProBaseinfoEntity>()
                        .eq(params.containsKey("cata"),"catag_id",params.get("cata"))
                        .eq(params.containsKey("cust_id"),"cust_id",params.get("cust_id"))
                        .eq(params.containsKey("cataid"),"navbarid",params.get("cataid"))
                        .like(ztc,"hdzt_ids",zt)
                        .like(zbcsc,"zbcs_ids",zbcs)
                        .like(yqc,"xc_ids",yq)
                        .like(zsdxc,"zsdx_ids",zsdx)
                        .like(yxgjc,"cfcs_ids",yxgj)
        );

        return new PageUtils(page);
    }

   public Long insertOneBackprimkey(BtCustomerProBaseinfoEntity entity){
        baseMapper.insertOneBackprimkey(entity);
        return entity.getId();
    }
    public  List<Map<String,Object>> getSalesPromotion(){
       List<Map<String,Object>>  backdata = new ArrayList<>();
        List<BtCustomerProBaseinfoEntity> searchbeanlist=null;
        List<ProSimpleVo> tembeanlist =null;
        Map<String,Object> content= null;
        //国际热销
        tembeanlist = new ArrayList<>();
        content= new HashMap<>();
        searchbeanlist = this.selectList(new EntityWrapper<BtCustomerProBaseinfoEntity>().eq("zfl_id","2"));
        if(searchbeanlist.size()>6){
            searchbeanlist = searchbeanlist.subList(0,6);
            for(BtCustomerProBaseinfoEntity tm :searchbeanlist){
                ProSimpleVo tbean =  new  ProSimpleVo();
                tbean.setImg(tm.getImgs().split(";")[0]);
                tbean.setLinkid(tm.getId());
                tbean.setName(tm.getTitle());
                tbean.setLink("detail/"+tm.getId());
                tembeanlist.add(tbean);
            }
            content.put("contentlist",tembeanlist);

        }else{
            for(BtCustomerProBaseinfoEntity tm :searchbeanlist){
                ProSimpleVo tbean =  new  ProSimpleVo();
                tbean.setImg(tm.getImgs().split(";")[0]);
                tbean.setLinkid(tm.getId());
                tbean.setName(tm.getTitle());
                tbean.setLink("detail/"+tm.getId());
                tembeanlist.add(tbean);
            }
            content.put("contentlist",tembeanlist);
        }
        content.put("name","国际游学");
        content.put("linkid","2");
        backdata.add(content);
        //国内热销
        content= new HashMap<>();
        tembeanlist = new ArrayList<>();
        searchbeanlist = this.selectList(new EntityWrapper<BtCustomerProBaseinfoEntity>().eq("zfl_id","1"));
        if(searchbeanlist.size()>6){
            searchbeanlist = searchbeanlist.subList(0,6);
            for(BtCustomerProBaseinfoEntity tm :searchbeanlist){
                ProSimpleVo tbean =  new  ProSimpleVo();
                tbean.setImg(tm.getImgs().split(";")[0]);
                tbean.setLinkid(tm.getId());
                tbean.setName(tm.getTitle());
                tbean.setLink("detail/"+tm.getId());
                tembeanlist.add(tbean);
            }
            content.put("contentlist",tembeanlist);
        }else{
            for(BtCustomerProBaseinfoEntity tm :searchbeanlist){
                ProSimpleVo tbean =  new  ProSimpleVo();
                tbean.setImg(tm.getImgs().split(";")[0]);
                tbean.setLinkid(tm.getId());
                tbean.setName(tm.getTitle());
                tbean.setLink("detail/"+tm.getId());
                tembeanlist.add(tbean);
            }
            content.put("contentlist",tembeanlist);
        }
        content.put("name","国内营");
        content.put("linkid","1");
        backdata.add(content);
        //亲子
        content= new HashMap<>();
        tembeanlist = new ArrayList<>();
        searchbeanlist = this.selectList(new EntityWrapper<BtCustomerProBaseinfoEntity>().eq("zfl_id","116"));
        if(searchbeanlist.size()>6){
            searchbeanlist = searchbeanlist.subList(0,6);
            for(BtCustomerProBaseinfoEntity tm :searchbeanlist){
                ProSimpleVo tbean =  new  ProSimpleVo();
                tbean.setImg(tm.getImgs().split(";")[0]);
                tbean.setLinkid(tm.getId());
                tbean.setName(tm.getTitle());
                tbean.setLink("detail/"+tm.getId());
                tembeanlist.add(tbean);
            }
            content.put("contentlist",tembeanlist);
        }else{
            for(BtCustomerProBaseinfoEntity tm :searchbeanlist){
                ProSimpleVo tbean =  new  ProSimpleVo();
                tbean.setImg(tm.getImgs().split(";")[0]);
                tbean.setLinkid(tm.getId());
                tbean.setName(tm.getTitle());
                tbean.setLink("detail/"+tm.getId());
                tembeanlist.add(tbean);
            }
            content.put("contentlist",tembeanlist);
        }
        content.put("name","周末营");
        content.put("linkid","3");
        backdata.add(content);
        return backdata;
    }

    /**
     *shouye国际
     */
    public Map<String,Object> getInternational(){
        Map<String,Object> backdata = new HashMap<>();
        List<ProSimpleVo> hotgj = getguojiyouxuecs();
        List<ProBaseInfoVo> rightkclist =null;
        List<Map<String,Object>> rightcontentlist=new ArrayList<>();
        Map<String,Object> rightcontent =null;
        backdata.put("hotgj",hotgj);
        backdata.put("hotzt",getguojiyouxuezt());
        //获取热门国家下的课程
        for(ProSimpleVo tm :hotgj){
            List<BtCustomerProBaseinfoEntity> tmpbeanlist = this.selectList(
                        new EntityWrapper<BtCustomerProBaseinfoEntity>().like("cfcs_desc",tm.getName()));
            rightkclist = new ArrayList<>();
            rightcontent =  new HashMap<>();
            for(BtCustomerProBaseinfoEntity tmm:tmpbeanlist){
                ProBaseInfoVo tkc = new ProBaseInfoVo();
                tkc.setName(tmm.getTitle());
                tkc.setLinkid(tmm.getId());
                tkc.setImg(tmm.getImgs().split(";")[0]);
                tkc.setPrice(1800);
                tkc.setPsnum(30);
                tkc.setLink("detail/"+tmm.getId());
                rightkclist.add(tkc);
            }
            rightcontent.put("linkid",tm.getLinkid());
            rightcontent.put("name",tm.getName());
            rightcontent.put("valuelist",rightkclist);
            rightcontentlist.add(rightcontent);
        }
        backdata.put("rightcontent",rightcontentlist);
        return backdata;
    }
    //获取国际旅游城市
   private List<ProSimpleVo> getguojiyouxuecs(){
       List<ProSimpleVo> tembeanlist =new ArrayList<>();
       BtCategroyManageEntity yxgjfl = btCategroyManageService.selectOne(
               new EntityWrapper<BtCategroyManageEntity>().eq("catatype","2,5"));
       List<BtCategroyManageEntity> balist = btCategroyManageService.selectList(
               new EntityWrapper<BtCategroyManageEntity>().eq("pid",yxgjfl.getId())
       );
       for(BtCategroyManageEntity tm: balist){
           ProSimpleVo tb = new  ProSimpleVo();
           tb.setLinkid(tm.getId());
           tb.setName(tm.getName());
           tb.setLink("link?cata=2&yxgj="+tm.getId());
           tembeanlist.add(tb);
       }
       return tembeanlist;
   }
    //获取国际热门主题
    private List<ProSimpleVo> getguojiyouxuezt(){
        List<ProSimpleVo> tembeanlist =new ArrayList<>();
        BtCategroyManageEntity yxgjfl = btCategroyManageService.selectOne(
                new EntityWrapper<BtCategroyManageEntity>().eq("catatype","2,1"));
        List<BtCategroyManageEntity> balist = btCategroyManageService.selectList(
                new EntityWrapper<BtCategroyManageEntity>().eq("pid",yxgjfl.getId())
        );
        for(BtCategroyManageEntity tm: balist){
            ProSimpleVo tb = new  ProSimpleVo();
            tb.setLinkid(tm.getId());
            tb.setName(tm.getName());
            tb.setLink("link?cata=2&zt="+tm.getId());
            tembeanlist.add(tb);
        }
        return tembeanlist;
    }
    /**
     * shouye国内
     */
    public Map<String,Object> getDomestic(){
        Map<String,Object> backdata = new HashMap<>();
        List<ProSimpleVo> hotgj = getguoneics();
        List<ProBaseInfoVo> rightkclist =null;
        List<Map<String,Object>> rightcontentlist=new ArrayList<>();
        Map<String,Object> rightcontent =null;
        backdata.put("hotcs",hotgj);
        backdata.put("hotzt",getguoneizt());
        //获取热门国家下的课程
        for(ProSimpleVo tm :hotgj){
            List<BtCustomerProBaseinfoEntity> tmpbeanlist = this.selectList(
                    new EntityWrapper<BtCustomerProBaseinfoEntity>().like("zbcs_desc",tm.getName()));
            rightkclist = new ArrayList<>();
            rightcontent =  new HashMap<>();
            for(BtCustomerProBaseinfoEntity tmm:tmpbeanlist){
                ProBaseInfoVo tkc = new ProBaseInfoVo();
                tkc.setName(tmm.getTitle());
                tkc.setLinkid(tmm.getId());
                tkc.setImg(tmm.getImgs().split(";")[0]);
                tkc.setPrice(800);
                tkc.setPsnum(35);
                tkc.setLink("detail/"+tmm.getId());
                rightkclist.add(tkc);
            }
            rightcontent.put("linkid",tm.getLinkid());
            rightcontent.put("name",tm.getName());
            rightcontent.put("valuelist",rightkclist);
            rightcontentlist.add(rightcontent);
        }
        backdata.put("rightcontent",rightcontentlist);
        return backdata;
    }
    //获取国内主题
    private List<ProSimpleVo> getguoneizt(){
        List<ProSimpleVo> tembeanlist =new ArrayList<>();
        BtCategroyManageEntity yxgjfl = btCategroyManageService.selectOne(
                new EntityWrapper<BtCategroyManageEntity>().eq("catatype","1,1"));
        List<BtCategroyManageEntity> balist = btCategroyManageService.selectList(
                new EntityWrapper<BtCategroyManageEntity>().eq("pid",yxgjfl.getId())
        );
        for(BtCategroyManageEntity tm: balist){
            List<BtCategroyManageEntity> subbalist = btCategroyManageService.selectList(
                    new EntityWrapper<BtCategroyManageEntity>().eq("pid",tm.getId()));
            for(BtCategroyManageEntity tmsub:subbalist){
                ProSimpleVo tb = new  ProSimpleVo();
                tb.setLinkid(tmsub.getId());
                tb.setName(tmsub.getName());
                tb.setLink("link?cata=1&zt="+tmsub.getId());
                tembeanlist.add(tb);
            }

        }
        return tembeanlist;
    }
    //获取国内城市
    private List<ProSimpleVo> getguoneics(){
        List<ProSimpleVo> tembeanlist =new ArrayList<>();
        BtCategroyManageEntity yxgjfl = btCategroyManageService.selectOne(
                new EntityWrapper<BtCategroyManageEntity>().eq("catatype","1,2"));
        List<BtCategroyManageEntity> balist = btCategroyManageService.selectList(
                new EntityWrapper<BtCategroyManageEntity>().eq("pid",yxgjfl.getId())
        );
        for(BtCategroyManageEntity tm: balist){
            List<BtCategroyManageEntity> subbalist = btCategroyManageService.selectList(
                    new EntityWrapper<BtCategroyManageEntity>().eq("pid",tm.getId()));
            for(BtCategroyManageEntity tmsub:subbalist){
                ProSimpleVo tb = new  ProSimpleVo();
                tb.setLinkid(tmsub.getId());
                tb.setName(tmsub.getName());
                tb.setLink("link?cata=1&zbcs="+tmsub.getId());
                tembeanlist.add(tb);
            }

        }
        return tembeanlist;
    }
    /**
     * shouye假日
     */
    public Map<String,Object> getHoliday(){
        Map<String,Object> backdata = new HashMap<>();
        List<ProSimpleVo> hotgj = getjairics();
        List<ProBaseInfoVo> rightkclist =null;
        List<Map<String,Object>> rightcontentlist=new ArrayList<>();
        Map<String,Object> rightcontent =null;
        backdata.put("hotcs",hotgj);
        backdata.put("hotzt",getjairizt());
        //获取热门国家下的课程
        for(ProSimpleVo tm :hotgj){
            List<BtCustomerProBaseinfoEntity> tmpbeanlist = this.selectList(
                    new EntityWrapper<BtCustomerProBaseinfoEntity>().like("zbcs_ids",String.valueOf(tm.getLinkid())).like("zbcs_desc",tm.getName()));
            rightkclist = new ArrayList<>();
            rightcontent =  new HashMap<>();
            for(BtCustomerProBaseinfoEntity tmm:tmpbeanlist){
                ProBaseInfoVo tkc = new ProBaseInfoVo();
                tkc.setName(tmm.getTitle());
                tkc.setLinkid(tmm.getId());
                tkc.setImg(tmm.getImgs().split(";")[0]);
                tkc.setPrice(500);
                tkc.setPsnum(35);
                tkc.setLink("detail/"+tmm.getId());
                rightkclist.add(tkc);
            }
            rightcontent.put("linkid",tm.getLinkid());
            rightcontent.put("name",tm.getName());
            rightcontent.put("valuelist",rightkclist);
            rightcontentlist.add(rightcontent);
        }
        backdata.put("rightcontent",rightcontentlist);
        return backdata;
    }
    //获取国内主题
    private List<ProSimpleVo> getjairizt(){
        List<ProSimpleVo> tembeanlist =new ArrayList<>();
        BtCategroyManageEntity yxgjfl = btCategroyManageService.selectOne(
                new EntityWrapper<BtCategroyManageEntity>().eq("catatype","3,2"));
        List<BtCategroyManageEntity> balist = btCategroyManageService.selectList(
                new EntityWrapper<BtCategroyManageEntity>().eq("pid",yxgjfl.getId()));
        for(BtCategroyManageEntity tm: balist){
            ProSimpleVo tb = new  ProSimpleVo();
            tb.setLinkid(tm.getId());
            tb.setName(tm.getName());
            tb.setLink("link?cata=3&zt="+tm.getId());
            tembeanlist.add(tb);
        }
        return tembeanlist;
    }
    //获取zhoumo城市
    private List<ProSimpleVo> getjairics(){
        List<ProSimpleVo> tembeanlist =new ArrayList<>();
        BtCategroyManageEntity yxgjfl = btCategroyManageService.selectOne(
                new EntityWrapper<BtCategroyManageEntity>().eq("catatype","3,2"));
        List<BtCategroyManageEntity> balist = btCategroyManageService.selectList(
                new EntityWrapper<BtCategroyManageEntity>().eq("pid",yxgjfl.getId()));
        for(BtCategroyManageEntity tm: balist){
            ProSimpleVo tb = new  ProSimpleVo();
            tb.setLinkid(tm.getId());
            tb.setName(tm.getName());
            tb.setLink("link?cata=3&zbcs="+tm.getId());
            tembeanlist.add(tb);
        }
        return tembeanlist;
    }
    public Map<String,Object> getGuojiYXGJ(String cid){
        Map<String,Object> backdata = new HashMap<>();
        List<ProSimpleVo> hotgj = getguojizbcs();
        List<BtCustomerProBaseinfoEntity> rightkclist =null;
        List<Map<String,Object>> rightcontentlist=new ArrayList<>();
        Map<String,Object> rightcontent =null;
        backdata.put("hotcs",hotgj);
        backdata.put("hotzt",getguojiyouxuezt());
        //获取热门国家下的课程
        for(ProSimpleVo tm :hotgj){
            List<BtCustomerProBaseinfoEntity> tmpbeanlist = this.selectList(
                    new EntityWrapper<BtCustomerProBaseinfoEntity>().like("cfcs_ids",cid).like("zbcs_ids",String.valueOf(tm.getLinkid())));
            rightkclist = new ArrayList<>();
            rightcontent =  new HashMap<>();
            for(BtCustomerProBaseinfoEntity tmm:tmpbeanlist){
                tmm.setImgs(tmm.getImgs().split(";")[0]);
                tmm.setLink("detail/"+tmm.getId());
                rightkclist.add(tmm);
            }
            rightcontent.put("linkid",tm.getLinkid());
            rightcontent.put("name",tm.getName());
            rightcontent.put("valuelist",rightkclist);
            rightcontentlist.add(rightcontent);
        }
        backdata.put("rightcontent",rightcontentlist);

        return backdata;
    }
    //获取国际举办城市
    private List<ProSimpleVo> getguojizbcs(){
        List<ProSimpleVo> tembeanlist =new ArrayList<>();
        BtCategroyManageEntity yxgjfl = btCategroyManageService.selectOne(new EntityWrapper<BtCategroyManageEntity>().eq("catatype","2,2"));
        List<BtCategroyManageEntity> balist = btCategroyManageService.selectList(
                new EntityWrapper<BtCategroyManageEntity>().eq("pid",yxgjfl.getId()));
        for(BtCategroyManageEntity tm: balist){
            ProSimpleVo tb = new  ProSimpleVo();
            tb.setLinkid(tm.getId());
            tb.setName(tm.getName());
            tb.setLink("link?cata=2&zbcs="+tm.getId());
            tembeanlist.add(tb);
        }
        return tembeanlist;
    }
    public List<Map<String,Object>> getGuoNeiDQFL(){
        List<Map<String,Object>> backdataList = new ArrayList<>();
        BtCategroyManageEntity diqufl = btCategroyManageService.selectOne(new EntityWrapper<BtCategroyManageEntity>().eq("catatype","1,2"));
        List<BtCategroyManageEntity> dqlist = btCategroyManageService.selectList(new EntityWrapper<BtCategroyManageEntity>().eq("pid",diqufl.getId()));
        Map<String,Object> backdata = null;
        List<ProSimpleVo> hotgj = getguoneics();
        List<ProSimpleVo>hotzt =getguoneizt();
        List<BtCustomerProBaseinfoEntity> rightkclist =null;
        for(BtCategroyManageEntity diqu: dqlist){
            backdata = new HashMap<>();
            backdata.put("title",diqu.getName());
            List<Map<String,Object>> rightcontentlist=new ArrayList<>();
            Map<String,Object> rightcontent =null;
            backdata.put("hotcs",hotgj);
            backdata.put("hotzt",hotzt);
            List<BtCategroyManageEntity> subcslist = btCategroyManageService.selectList(new EntityWrapper<BtCategroyManageEntity>().eq("pid",diqu.getId()));
            //获取城市下的
            for(BtCategroyManageEntity tm :subcslist){
                List<BtCustomerProBaseinfoEntity> tmpbeanlist = this.selectList(
                        new EntityWrapper<BtCustomerProBaseinfoEntity>().like("zbcs_desc",tm.getName()));
                rightkclist = new ArrayList<>();
                rightcontent =  new HashMap<>();
                for(BtCustomerProBaseinfoEntity tmm:tmpbeanlist){
                    tmm.setImgs(tmm.getImgs().split(";")[0]);
                    tmm.setLink("detail/"+tmm.getId());
                    rightkclist.add(tmm);
                }
                rightcontent.put("linkid",tm.getId());
                rightcontent.put("name",tm.getName());
                rightcontent.put("valuelist",rightkclist);
                rightcontentlist.add(rightcontent);
            }
            backdata.put("rightcontent",rightcontentlist);
            backdataList.add(backdata);
        }
        return backdataList;
    }
}
